package com.yuhs.zixing.study.thread.juc.code001;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @description 怎么创建线程
 * @author: yuhs
 * @date 2021/11/17 8:22 下午
 */
public class C02_HowToCreateThread {
    static class MyThread extends Thread {
        @Override
        public void run() {
            System.out.println("我是继承方式创建的线程");
        }
    }

    static class MyRunThread implements Runnable {
        @Override
        public void run() {
            System.out.println("我是实现方式创建的线程");
        }
    }

    public static void main(String[] args) {
        new MyThread().start();
        new Thread(new MyRunThread()).start();
        new Thread(() -> System.out.println("lambda 表达式")).start();

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("定时器线程执行了...");
            }
        }, 0, 1000); //延迟0，周期1s


        System.out.println("主线程");
    }
}
